package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-05-22
 * Time: 23:07
 */
//自建线程等待main线程
public class Demo15 {
    public static void main(String[] args) throws InterruptedException {
        Thread mainThread = Thread.currentThread();

        Thread thread = new Thread(() -> {
            try {
                System.out.println("thread线程开始等待main线程");
                mainThread.join();
                System.out.println("thread线程结束等待main线程");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        thread.start();
        Thread.sleep(3000);
        System.out.println("main结束");
    }
}
